package com.example.localareanetworkchat.persistence.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.fasterxml.jackson.annotation.JsonProperty

@Entity(tableName = "chat_message")
data class ChatMessage(
    @JsonProperty("id")
    @PrimaryKey(autoGenerate = true)
    val id: Long,
    @JsonProperty("groupId")
    @ColumnInfo(name = "group_id")
    val groupId: Long,
    @JsonProperty("groupName")
    @ColumnInfo(name = "group_name")
    val groupName: String,
    @JsonProperty("userId")
    @ColumnInfo(name = "user_id")
    val userId: Long,
    @JsonProperty("userName")
    @ColumnInfo(name = "user_name")
    val userName: String,
    @JsonProperty("uid")
    @ColumnInfo(name = "uid")
    val uid: String,
    @JsonProperty("chatGroupId")
    @ColumnInfo(name = "chat_group_id")
    val chatGroupId: String,
    @JsonProperty("connectIp")
    @ColumnInfo(name = "connect_ip")
    val connectIp: String,
    @JsonProperty("connectIpInt")
    @ColumnInfo(name = "connect_ip_int")
    val connectIpInt: Int,
    @JsonProperty("message")
    @ColumnInfo(name = "message")
    var message: String,
    @JsonProperty("messageType")
    @ColumnInfo(name = "message_type")
    val messageType: String,
    @JsonProperty("messageReceiveTimestamp")
    @ColumnInfo(name = "message_receive_timestamp")
    var messageReceiveTimestamp: Long
)

data class ChatMessageItem(
    val id: Long,
    val groupId: Long,
    val groupName: String,
    val userId: Long,
    val userName: String,
    val uid: String,
    val chatGroupId: String,
    val connectIp: String,
    val connectIpInt: Int,
    val message: String,
    val messageType: String,
    val messageReceiveTimestamp: Long
) {
    var userSelfSendFlag = 0

    constructor(chatMessage: ChatMessage) : this(chatMessage.id,chatMessage.groupId,chatMessage.groupName,chatMessage.userId,chatMessage.userName,chatMessage.uid,
    chatMessage.chatGroupId,chatMessage.connectIp,chatMessage.connectIpInt,chatMessage.message,chatMessage.messageType,chatMessage.messageReceiveTimestamp)
}

class ChatMessageType {
    companion object {
        const val PLAIN_TEXT = "PLAIN_TEXT"
    }
}
